﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace dzs.Web.supply
{
    public partial class ListArrivalBill : System.Web.UI.Page
    {
        Maticsoft.BLL.monthSupplayPlan msm = new Maticsoft.BLL.monthSupplayPlan();
        //Maticsoft.BLL.supplyPlan sm = new Maticsoft.BLL.supplyPlan();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    Bind(user_id);
                }
                //Bind(11);
            }
        }

        private void Bind(int user_id)
        {
            StringBuilder str = new StringBuilder();

            str.Append(" supplyPlanUser=" + user_id);
            str.Append(" and status='1' and (arrivalGoodsBillStatus is null or arrivalGoodsBillStatus ='') ");//到货验收单确认状态


            if (!string.IsNullOrEmpty(txt_material.Text))
            {
                str.Append(" and material like '%" + txt_material.Text + "%' ");
            }
            if (!string.IsNullOrEmpty(txt_projectName.Text))
            {
                str.Append(" and projectName like '%" + txt_projectName.Text + "%' ");
            }

            DataSet ds = msm.GetList(str.ToString());
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

            DataSet ds_config = new dzs.BLL.configinfo().GetList("");

            this.lbl_resultDate.Text = ds_config.Tables[0].Rows[0]["ygyjs"] + "号";
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_confirmFrist")
            {
                string monthSupplyPlanId = e.CommandArgument.ToString();

                if (Session["login"] != null)
                {
                    DataSet ds_login = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds_login.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds_login.Tables[0].Rows[0]["user_id"].ToString());

                    Maticsoft.Model.monthSupplayPlan m = msm.GetModel(int.Parse(monthSupplyPlanId));

                    m.arrivalGoodsBillStatus = "已确认";
                    m.arrivalGoodsBillTime = DateTime.Now;

                    if (msm.Update(m))
                    {
                        Maticsoft.Common.MessageBox.Show(this, "到货验收单确认成功！确认时间:"+m.arrivalGoodsBillTime);

                        Bind(user_id);
                    }

                    


                }


            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }

        }

        protected void btn_sel_Click(object sender, EventArgs e)
        {
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }
        }
    }
}